package com.mtw.bbs.bbsUser.controller.open;


import com.mtw.bbs.article.feign.LikeClient;
import com.mtw.bbs.bbsUser.pojo.entity.User;
import com.mtw.bbs.bbsUser.pojo.vo.UserCountVO;
import com.mtw.bbs.bbsUser.service.UserFollowService;
import com.mtw.bbs.bbsUser.service.UserService;
import com.mtw.bbs.common.core.vo.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 关注接口层
 */
@Slf4j
@RestController
@RequestMapping("open/follow")
@RequiredArgsConstructor
public class OpenFollowController {

    private final LikeClient likeClient;
    private final UserService userService;
    private final UserFollowService userFollowService;




    /**
     * 获取指定用户的关注数与粉丝数
     *
     */
    @GetMapping(value = "/follow_and_fans_count/{username}")
    public Result getUserFollowAndFansCount(@PathVariable("username") String username) {

        UserCountVO vo = new UserCountVO();
        User user = userService.getUserInfoByUsername(username);
        if (user == null) {
            return Result.success(vo);
        }
        Integer like = likeClient.getUserLikeCount(user.getId()).getData();
        Integer follow = userFollowService.countOfFollow(user.getId());
        Integer fans = userFollowService.countOfFans(user.getId());
        vo.setFans(fans);
        vo.setFollow(follow);
        vo.setLike(like);
        return Result.success(vo);
    }







}
